package export
{
	import com.dusk.util.ResUtil;
	import com.game.data.constant.ConfigConst;
	import com.game.manager.NotificationManager;
	
	import config.Config;
	
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	
	public class EndlessMode extends MovieClip
	{
		
		public function EndlessMode()
		{
			this._textFormat = new TextFormat();
			super();
			this._txt = this.createText(455, 365, 50, 28);
			this._txt.text = this.levelnum.toString();
			this.addChild(this._txt);
			this.gc = Config.getIns();
			this.addEventListener(Event.ADDED_TO_STAGE, this.added, false, 0, true);
			this.addEventListener(Event.REMOVED_FROM_STAGE, this.removed, false, 0, true);
		}
		
		private var nextlevel:MovieClip;
		private var lastlevel:MovieClip;
		private var acceptBtn:MovieClip;
		private var refuseBtn:MovieClip;
		private var _txt:TextField;
		private var _textFormat:TextFormat;
		private var levelnum:int = 101;
		private var gc:Config;
		
		private function createText(param1:int, param2:int, param3:int, param4:int):TextField
		{
			var _loc5_:TextField = new TextField();
			this._textFormat.font = ConfigConst.GAME_CONFIG_FONT;
			this._textFormat.size = 20;
			this._textFormat.color = 16777215;
			_loc5_.embedFonts = true;
			_loc5_.defaultTextFormat = this._textFormat;
			this._textFormat.align = TextFormatAlign.CENTER;
			_loc5_.x = param1;
			_loc5_.y = param2;
			_loc5_.width = param3;
			_loc5_.height = param4;
			_loc5_.autoSize = TextFieldAutoSize.CENTER;
			return _loc5_;
		}
		
		private function refreshtext():void
		{
			this._txt.text = this.levelnum.toString();
		}
		
		private function afterchoose():void
		{
			if (this.gc.pWorld.getBaseLevelListener())
			{
				(this.gc.pWorld.getBaseLevelListener() as StageListener981).dataObj.curWave = this.gc.ObjectData.endlesslevel;
				(this.gc.pWorld.getBaseLevelListener() as StageListener981).nextWave();
			}
			if (this.parent)
			{
				this.parent.removeChild(this);
			}
		}
		
		private function added(param1:Event):void
		{
			this.nextlevel = ResUtil.getNewObj("export.nextpageBtn") as MovieClip;
			this.nextlevel.x = 510;
			this.nextlevel.y = 360;
			this.addChild(this.nextlevel);
			this.nextlevel.buttonMode = true;
			this.nextlevel.gotoAndStop(1);
			this.nextlevel.addEventListener(MouseEvent.CLICK, this.nextclick);
			this.nextlevel.addEventListener(MouseEvent.ROLL_OVER, this.mOver);
			this.nextlevel.addEventListener(MouseEvent.MOUSE_OUT, this.mOut);
			this.lastlevel = ResUtil.getNewObj("export.lastpageBtn") as MovieClip;
			this.lastlevel.x = 400;
			this.lastlevel.y = 360;
			this.addChild(this.lastlevel);
			this.lastlevel.buttonMode = true;
			this.lastlevel.gotoAndStop(1);
			this.lastlevel.addEventListener(MouseEvent.CLICK, this.lastclick);
			this.lastlevel.addEventListener(MouseEvent.ROLL_OVER, this.mOver);
			this.lastlevel.addEventListener(MouseEvent.MOUSE_OUT, this.mOut);
			this.acceptBtn = ResUtil.getNewObj("export.okBtn") as MovieClip;
			this.acceptBtn.x = 330;
			this.acceptBtn.y = 360;
			this.addChild(this.acceptBtn);
			this.acceptBtn.buttonMode = true;
			this.acceptBtn.gotoAndStop(1);
			this.acceptBtn.addEventListener(MouseEvent.CLICK, this.changeok);
			this.acceptBtn.addEventListener(MouseEvent.ROLL_OVER, this.mOver);
			this.acceptBtn.addEventListener(MouseEvent.MOUSE_OUT, this.mOut);
			this.refuseBtn = ResUtil.getNewObj("export.changeBtn") as MovieClip;
			this.refuseBtn.x = 560;
			this.refuseBtn.y = 360;
			this.addChild(this.refuseBtn);
			this.refuseBtn.buttonMode = true;
			this.refuseBtn.gotoAndStop(1);
			this.refuseBtn.addEventListener(MouseEvent.CLICK, this.changeno);
			this.refuseBtn.addEventListener(MouseEvent.ROLL_OVER, this.mOver);
			this.refuseBtn.addEventListener(MouseEvent.MOUSE_OUT, this.mOut);
		}
		
		private function removed(param1:Event):void
		{
			this.nextlevel.removeEventListener(MouseEvent.CLICK, this.nextclick);
			this.nextlevel.removeEventListener(MouseEvent.ROLL_OVER, this.mOver);
			this.nextlevel.removeEventListener(MouseEvent.MOUSE_OUT, this.mOut);
			this.nextlevel = null;
			this.lastlevel.removeEventListener(MouseEvent.CLICK, this.lastclick);
			this.lastlevel.removeEventListener(MouseEvent.ROLL_OVER, this.mOver);
			this.lastlevel.removeEventListener(MouseEvent.MOUSE_OUT, this.mOut);
			this.lastlevel = null;
			this.acceptBtn.removeEventListener(MouseEvent.CLICK, this.changeok);
			this.acceptBtn.removeEventListener(MouseEvent.ROLL_OVER, this.mOver);
			this.acceptBtn.removeEventListener(MouseEvent.MOUSE_OUT, this.mOut);
			this.acceptBtn = null;
			this.refuseBtn.removeEventListener(MouseEvent.CLICK, this.changeno);
			this.refuseBtn.removeEventListener(MouseEvent.ROLL_OVER, this.mOver);
			this.refuseBtn.removeEventListener(MouseEvent.MOUSE_OUT, this.mOut);
			this.refuseBtn = null;
		}
		
		private function mOver(param1:MouseEvent):void
		{
			param1.currentTarget.gotoAndStop(3);
		}
		
		private function mOut(param1:MouseEvent):void
		{
			param1.currentTarget.gotoAndStop(1);
		}
		
		private function lastclick(param1:MouseEvent):void
		{
			if (this.levelnum <= 1)
			{
				return;
			}
			this.levelnum -= 10;
			this.refreshtext();
		}
		
		private function nextclick(param1:MouseEvent):void
		{
			if (this.levelnum >= 211)
			{
				NotificationManager.alert("最高只能从211波开始~");
				return;
			}
			this.levelnum += 10;
			this.refreshtext();
		}
		
		private function changeok(param1:MouseEvent):void
		{
			this.gc.ObjectData.endlesslevel = this.levelnum - 1;
			this.afterchoose();
		}
		
		private function changeno(param1:MouseEvent):void
		{
			this.gc.ObjectData.endlesslevel = 0;
			this.afterchoose();
		}
	}
}
